package com.doit.day01;

import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class HFileBuilder extends Mapper<LongWritable, Text, ImmutableBytesWritable, KeyValue> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, ImmutableBytesWritable, KeyValue>.Context context) throws IOException, InterruptedException {
        //1,991697,rdTyE,朋友,PnZUfQrf,平安少儿百万全保险,wROOs,2011-11-21,2011-11-22,2011-11-23,2012-11-20,2012-11-20,4264,1397,42641397,现金,0
        String str = value.toString();
        String[] arr = str.split(",");
        /**
         * policy_no                          -- 保单号
         * app_applicant_user_id              -- 投保人id
         * applicant_name                     -- 投保人姓名
         * applicant_relation                 -- 与被保人关系
         * product_code                       -- 产品代码
         * product_name                       -- 产品名称
         * agent_code                         -- 主招揽业务员代码
         * application_date                   -- 投保日期
         * underwrite_date                    -- 承保日期
         * effective_date                     -- 生效日期
         * maturity_date                      -- 满期日期
         * payment_to_date                    -- 缴至日期
         * modal_standard_premium             -- 期缴标准保费
         * modal_add_premium                  -- 期缴其他加费
         * modal_total_premium                -- 期缴保费合计
         * app_pay_type_code                  -- 支付类型
         * renewal_flag                       -- 续保标识(0:新保,1:续保)
         */
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f1".getBytes(),"app_applicant_user_id".getBytes(),arr[1].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f1".getBytes(),"applicant_name".getBytes(),arr[2].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f1".getBytes(),"applicant_relation".getBytes(),arr[3].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f1".getBytes(),"product_code".getBytes(),arr[4].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f1".getBytes(),"product_name".getBytes(),arr[5].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f1".getBytes(),"agent_code".getBytes(),arr[6].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"application_date".getBytes(),arr[7].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"underwrite_date".getBytes(),arr[8].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"effective_date".getBytes(),arr[9].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"maturity_date".getBytes(),arr[10].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"payment_to_date".getBytes(),arr[11].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"modal_standard_premium".getBytes(),arr[12].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"modal_add_premium".getBytes(),arr[13].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"modal_total_premium".getBytes(),arr[14].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"app_pay_type_code".getBytes(),arr[15].getBytes()));
        context.write(new ImmutableBytesWritable(arr[0].getBytes()),new KeyValue(arr[0].getBytes(),"f2".getBytes(),"renewal_flag".getBytes(),arr[16].getBytes()));
    }
}
